#include<bits/stdc++.h>
using namespace std;

struct node {
	int w, s;
} a[50005];

int fun(int n, vector<int> w, vector<int> s) {
	for (int i = 0; i < n; i++) {
		a[i] = {w[i], s[i]};
	}

	sort(a, a + n, [](node x, node y) {
		return x.w - y.s < y.w - x.s;
	});

	int pre = a[0].w, ans = -a[0].s;
	for (int i = 1; i < n; i++) {
		ans = max(ans, pre - a[i].s);
		pre += a[i].w;
	}
	return ans;
}

signed main() {
	int n;
	cin >> n;
	vector<int> w(n), s(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> s[i];
	}
	cout << fun(n, w, s);
	return 0;
}
